function getRect(selector) {
    return new Promise((resolve) => {
        uni.createSelectorQuery()
            .in(this)
            .select(selector)
            .boundingClientRect()
            .exec((rect = []) => resolve(rect[0]));
    });
}
function getAllRect(selector) {
    return new Promise((resolve) => {
        uni.createSelectorQuery()
            .in(this)
            .selectAll(selector)
            .boundingClientRect()
            .exec((rect = []) => resolve(rect[0]));
    });
}
module.exports = {
    methods: {
        //选取元素
        getRect
        // 选取所有元素
        , getAllRect
        // 滚动到居中位置
        , scrollIntoView({
            //当前索引
            scrollIndex
            // scroll-view class或者 id
            , scrollClass
            // scroll-view item class
            , scrollItemClass
            // scroll-view data  scrollleft -- model
            , scrollLeftModel
        }) {
            const vm = this;
            return Promise.all([
                getAllRect.call(vm, scrollItemClass),
                getRect.call(vm, scrollClass),
            ]).then(([tabRects, navRect]) => {
                const tabRect = tabRects[scrollIndex];
                const offsetLeft = tabRects
                    .slice(0, scrollIndex)
                    .reduce((prev, curr) => prev + curr.width, 0);
                const scrollToLeft = offsetLeft - (navRect.width - tabRect.width) / 2;
                if (scrollLeftModel) {
                    vm.scrollLeftModel = scrollToLeft;
                }
                return Promise.resolve(scrollLeftModel);

            });
        },
    },
}